package com.hzgj.bcl.soa.command;

import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.hzgj.bcl.stats.RedisKey;
import redis.clients.jedis.Tuple;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Created by Administrator on 2016/9/2.
 */
public class InvokeDyTimeCommand extends InvokeDyCommand {

    @Override
    String handleDyData(String baseKey, long target) {
        Set<Tuple> tuples = redisClient.zrangeByScoreWithScores(RedisKey.getSpanTp75(baseKey), target, target);
        List<Map<String, Object>> result = Lists.newArrayList();
        result.add(buildTuple(tuples, "tp75", target));
        tuples = redisClient.zrangeByScoreWithScores(RedisKey.getSpanTp95(baseKey), target, target);
        result.add(buildTuple(tuples, "tp95", target));
        tuples = redisClient.zrangeByScoreWithScores(RedisKey.getSpanTp99(baseKey), target, target);
        result.add(buildTuple(tuples, "tp99", target));
        tuples = redisClient.zrangeByScoreWithScores(RedisKey.getSpanTp999(baseKey), target, target);
        result.add(buildTuple(tuples, "tp999", target));
        return JSON.toJSONString(result);
    }


    @Override
    public String getName() {
        return "invoke_dy_time";
    }
}
